﻿using University.Workshop.Business;
using University.Workshop.DataAccess;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using System;
using University.Workshop.Model;

namespace University.Workshop.Tests
{
    
    
    /// <summary>
    ///This is a test class for WebmasterDataAccessTest and is intended
    ///to contain all WebmasterDataAccessTest Unit Tests
    ///</summary>
    [TestClass()]
    public class WebmasterDataAccessTest
    {


        private TestContext testContextInstance;

        /// <summary>
        ///Gets or sets the test context which provides
        ///information about and functionality for the current test run.
        ///</summary>
        public TestContext TestContext
        {
            get
            {
                return testContextInstance;
            }
            set
            {
                testContextInstance = value;
            }
        }

        #region Additional test attributes
        // 
        //You can use the following additional attributes as you write your tests:
        //
        //Use ClassInitialize to run code before running the first test in the class
        //[ClassInitialize()]
        //public static void MyClassInitialize(TestContext testContext)
        //{
        //}
        //
        //Use ClassCleanup to run code after all tests in a class have run
        //[ClassCleanup()]
        //public static void MyClassCleanup()
        //{
        //}
        //
        //Use TestInitialize to run code before running each test
        //[TestInitialize()]
        //public void MyTestInitialize()
        //{
        //}
        //
        //Use TestCleanup to run code after each test has run
        //[TestCleanup()]
        //public void MyTestCleanup()
        //{
        //}
        //
        #endregion


        /// <summary>
        ///A test for GetWebmasterByUserId
        ///</summary>
        [TestMethod()]
        public void GetWebmasterByUserIdTest()
        {
            string firstName = "Pablo";
            string lastName = "Marmol";
            char gender = 'M';
            Random rand = new Random();
            DateTime birthday = DateTime.Now.AddYears(-18);
            string email = "pablo" + rand.Next(400) + "@email.com";
            string password = "qwert1";
            string rePassword = "qwert1";
            string department = "Chuquisaca";
            string city = "Sucre";
            string movilephone = "" + rand.Next(79999999);
            string phone = "" + rand.Next(4999999);
            UserRegistrationManager.RegisterUser(firstName, lastName, gender, birthday, email, password, rePassword, department, city, movilephone, phone);
            long userId = UserDataAccess.GetUserByEmail(email).Id;
            Webmaster newWebmaster = new Webmaster { UserId = userId, CanRespondTickets = true, CanSetWebmasters = true };
            Webmaster expected = WebmasterDataAccess.InsertWebmaster(newWebmaster);
            Webmaster actual;
            actual = WebmasterDataAccess.GetWebmasterByUserId(userId);
            Assert.AreEqual(expected.Id, actual.Id);
        }

        /// <summary>
        ///A test for InsertWebmaster
        ///</summary>
        [TestMethod()]
        public void InsertWebmasterTest()
        {
            string firstName = "Enrique"; 
            string lastName = "Choke"; 
            char gender = 'M'; 
            Random rand = new Random();
            DateTime birthday = DateTime.Now.AddYears(-18);
            string email = "enrique" + rand.Next(400) + "@gmail.com"; 
            string password = "qwert1"; 
            string rePassword = "qwert1"; 
            string department = "Oruro"; 
            string city = "Cercado"; 
            string movilephone = "" + rand.Next(79999999); 
            string phone = "" + rand.Next(4999999); 
            UserRegistrationManager.RegisterUser(firstName, lastName, gender, birthday, email, password, rePassword, department, city, movilephone, phone);
            long userId = UserDataAccess.GetUserByEmail(email).Id;
            Webmaster newWebmaster = new Webmaster{UserId = userId, CanRespondTickets = true, CanSetWebmasters = true}; 
            Webmaster actual;
            actual = WebmasterDataAccess.InsertWebmaster(newWebmaster);
            Assert.AreEqual(userId, actual.UserId);
        }
    }
}
